<template>
	<!-- TODO  多数据源下拉框公共组件 -->
	<div style="width: 100%">
		<el-select v-model="dataSourceValue" @change="dataSorceSelectChange" placeholder="请选择">
			<el-option v-for="item in dataSourceOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
		</el-select>
	</div>
</template>
<script>
	import { request } from '@/utils/request'
	import eventBus from '@/utils/eventBus.js'
	import { getMoreDataSource, getDataSourceById } from '@/system/api/public'
	export default {
		data() {
			return {
				dataSourceOptions: [],
				dataSourceValue: 2,
			}
		},
		created() {
			//页面初始化时请求系统数据，多数据源数据选择时更新
			// {microId:null}
			getMoreDataSource().then(res => {
				this.dataSourceOptions = []
				res.info.forEach(item => {
					if (item.id) {
						let obj = {}
						obj.value = item.id
						obj.label = item.name
						this.dataSourceOptions.push(obj)
					}
				})
				this.$emit('microIds', this.dataSourceOptions[0].value)
				// this.dataSourceOptions.push({
				//   value: null,
				//   label: "系统",
				// });
				// this.dataSourceValue = this.dataSourceOptions[
				//   this.dataSourceOptions.length - 1
				// ].value;
				// eventBus.$emit('dataSourceSelectChange',null)
			})
		},
		methods: {
			dataSorceSelectChange(e) {
				//   let dataObj = {};
				//   dataObj.pid = 0;
				//   dataObj.parentId = 0;
				//   dataObj.pid = 0;
				//   dataObj.microId = e;
				//   getDataSourceById(dataObj).then((res) => {
				//     console.log(JSON.stringify(res));
				//   });
				//把事件传值到父组件
				eventBus.$emit('dataSourceSelectChange', e)
				this.$emit('dataSourceSelectChange', e)
			},
		},
	}
</script>
<style lang="scss" scoped>
	.el-select {
		width: 100%;
	}
</style>
